package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 马宇航
 * @Todo: TODO
 * @DateTime: 22/04/14/0014 下午 3:10
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RequestMapping("/rbacManager")
public class RbacManagerController {
    @Autowired
    RbacManagerService rbacManagerService;
    @GetMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable int currentPage,@PathVariable int pageSize){
        return  rbacManagerService.findAll(currentPage,pageSize);
    }
    @RequestMapping("/testRole")
    //这个controller方法，需要一个角色，才允许你访问我的controller
    @RequiresRoles("普通员工")
    public ResponseEntity testRole(){
        return new ResponseEntity(200,"拥有普通员工的权限，才能查出这句话",null);
    }
    @RequestMapping("/testPerm")
    //这个controller方法，需要一个角色，才允许你访问我的controller
    @RequiresPermissions(value = {"perm:list","perm:update"},logical = Logical.OR)
    public ResponseEntity testPerm(){
        return new ResponseEntity(200,"拥有list或update的权限，才能查出这句话",null);
    }
}
